<?php
// 本类由系统自动生成，仅供测试用途
class IndexAction extends BaseAction {
    public function index(){
        //一个分类带两条新闻
        $newsType=M('newstypes')->select();
        foreach($newsType as $k=>$v){
            $v["news"]=M('newsarticles')->where("typeId={$v['typeId']}")->order("dateandtime desc")->limit(0,2)->select();
           $newsType[$k]=$v;
        }
        //热点要闻
        $hotNews=M()->query("select * from newsarticles a inner join newstypes b on a.typeId=b.typeId order by hints desc limit 0,6");
       //新闻总数
        $newsCount=M('newsarticles')->count();
        $this->assign('newsCount',$newsCount);
        $this->assign('newsType',$newsType);
        $this->assign("hotNews",$hotNews);
        $this->display();
    }
    //验证码
    public function image(){
        import("ORG.Util.Image");
       Image::buildImageVerify();
    }
    //登录进入后台
    public function admin(){
        $checkCode=md5($_POST['checkCode']);
        $truecode=$_SESSION['verify'];
       //var_dump($_POST);exit;
       if($checkCode==$truecode){
          $userInfo=M('manager')->where($_POST)->find();
          if($userInfo==null){
              $this->success('用户名或密码错误！',__APP__."/Index/index.html");
          }else{
             // var_dump($userInfo);exit;
              session('[start]');
              session('userMsg',$userInfo);
              
              $this->success("登录成功！","/PSD1602/myself/ThinkPHP-news/admin.php");
          }
       }else{
          $this->success("验证码错误",__APP__."/Index/index.html");
          
       }
    }
}

